import 'package:finance_app/src/entities/setting_app_entity.dart';

settingAppEntityFromJson(SettingAppEntity data, Map<String, dynamic> json) {
	if (json['country_code'] != null) {
		data.countryCode = (json['country_code'] as List).map((v) => SettingAppCountryCode().fromJson(v)).toList();
	}
	if (json['business_type'] != null) {
		data.businessType = (json['business_type'] as List).map((v) => SettingAppBusinessType().fromJson(v)).toList();
	}
	if (json['industry_type'] != null) {
		data.industryType = (json['industry_type'] as List).map((v) => SettingAppIndustryType().fromJson(v)).toList();
	}
	if (json['ios_status'] != null) {
		data.iosStatus = json['ios_status'] is String
				? int.tryParse(json['ios_status'])
				: json['ios_status'].toInt();
	}
	if (json['ios_register_status'] != null) {
		data.iosRegisterStatus = json['ios_register_status'] is String
				? int.tryParse(json['ios_register_status'])
				: json['ios_register_status'].toInt();
	}
	if (json['android_status'] != null) {
		data.androidStatus = json['android_status'] is String
				? int.tryParse(json['android_status'])
				: json['android_status'].toInt();
	}
	if (json['android_register_status'] != null) {
		data.androidRegisterStatus = json['android_register_status'] is String
				? int.tryParse(json['android_register_status'])
				: json['android_register_status'].toInt();
	}
	return data;
}

Map<String, dynamic> settingAppEntityToJson(SettingAppEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['country_code'] =  entity.countryCode?.map((v) => v.toJson())?.toList();
	data['business_type'] =  entity.businessType?.map((v) => v.toJson())?.toList();
	data['industry_type'] =  entity.industryType?.map((v) => v.toJson())?.toList();
	data['ios_status'] = entity.iosStatus;
	data['ios_register_status'] = entity.iosRegisterStatus;
	data['android_status'] = entity.androidStatus;
	data['android_register_status'] = entity.androidRegisterStatus;
	return data;
}

settingAppCountryCodeFromJson(SettingAppCountryCode data, Map<String, dynamic> json) {
	if (json['country_code'] != null) {
		data.countryCode = json['country_code'].toString();
	}
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['is_favorite'] != null) {
		data.isFavorite = json['is_favorite'] is String
				? int.tryParse(json['is_favorite'])
				: json['is_favorite'].toInt();
	}
	if (json['group'] != null) {
		data.group = json['group'].toString();
	}
	return data;
}

Map<String, dynamic> settingAppCountryCodeToJson(SettingAppCountryCode entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['country_code'] = entity.countryCode;
	data['name'] = entity.name;
	data['is_favorite'] = entity.isFavorite;
	data['group'] = entity.group;
	return data;
}

settingAppBusinessTypeFromJson(SettingAppBusinessType data, Map<String, dynamic> json) {
	if (json['data_type'] != null) {
		data.dataType = json['data_type'].toString();
	}
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['key'] != null) {
		data.key = json['key'].toString();
	}
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	return data;
}

Map<String, dynamic> settingAppBusinessTypeToJson(SettingAppBusinessType entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['data_type'] = entity.dataType;
	data['id'] = entity.id;
	data['key'] = entity.key;
	data['name'] = entity.name;
	return data;
}

settingAppIndustryTypeFromJson(SettingAppIndustryType data, Map<String, dynamic> json) {
	if (json['data_type'] != null) {
		data.dataType = json['data_type'].toString();
	}
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['key'] != null) {
		data.key = json['key'].toString();
	}
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['business_type'] != null) {
		data.businessType = json['business_type'].toString();
	}
	return data;
}

Map<String, dynamic> settingAppIndustryTypeToJson(SettingAppIndustryType entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['data_type'] = entity.dataType;
	data['id'] = entity.id;
	data['key'] = entity.key;
	data['name'] = entity.name;
	data['business_type'] = entity.businessType;
	return data;
}